<?php

/**
 * 
 */
class Default_ImagemController extends Zend_Controller_Action
{
    /**
     *
     * @access public
     * @return void
     */
    public function viewAction()
    {
		$id = $this->_getParam( 'id' );
		$w 	= $this->_getParam( 'w' );
		$h 	= $this->_getParam( 'h' );

		$dbTable = App_Model_DbTable_Factory::get( 'Imagem' );

		$row = $dbTable->find( $id );
		
		if ( count( $row ) < 1 ) {
	    
	    	$image = APPLICATION_PATH . '/../public/images/no_picture.png';
	    	$thumb = PhpThumb_PhpThumbFactory::create( $image );
	    
		} else {
			
	    	$image = $row->current()->img_arquivo;
	    	$thumb = PhpThumb_PhpThumbFactory::create( $image, array(), true );
	
		}

		$this->_helper->layout->disableLayout();
		$this->_helper->viewRenderer->setNoRender();

		if ( $w && $h )
	    	$thumb->adaptiveResize( $w, $h );

		$thumb->show();
    }
}